home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / patch / pagestream / pgs32tu3 / scripts.lha / FontSpec.rexx < prev    next >
OS/2 REXX Batch file  |  1996-11-14  |  10KB  |  329 lines

  1. /* $VER: FontSpec.rexx 3.1c (14.11.96)
  2.    Copyright 1996 SoftLogik Publishing Corporation
  3.    May not be distributed without SoftLogik Publishing Corporation's express written permission */
  4.  
  5. OPTIONS RESULTS
  6. TRACE OFF
  7.  
  8. /* Make sure rexx support is opened */
  9. IF ~SHOW('L','rexxsupport.library') THEN
  10.    CALL ADDLIB('rexxsupport.library',0,-30)
  11.  
  12. ADDRESS 'PAGESTREAM'
  13.  
  14. /* DEFINES      */
  15.     pfontcount=0
  16.     totalfonts=0
  17.     cancel=9
  18. /* specsize   */
  19.     big=0
  20.     small=1
  21. /* whichfonts */
  22.     all=0
  23.     select=1
  24.  
  25. /* MAIN LOOP  */
  26. choice=INSTRUCT()                                        /* find out what to print */
  27. if choice~=cancel then do
  28.         call FINDFONTS()
  29.         call SORTIFONTS()
  30.         if whichfonts=select then call CHOOSEFONTS()    /* choose which fonts to print */
  31.         else do
  32.             do i=1 to ifontcount
  33.                 pfonts.i=ifonts.i
  34.             end
  35.             pfontcount=ifontcount
  36.         end
  37.         if specsize=small then sDocName="fontspec6.doc"
  38.             else sDocName="fontspec1.doc"
  39.         'opendocument file "pagestream3:scripts/'sDocName'"'
  40.             
  41.         call PRINTFONTS()
  42. end
  43. EXIT
  44.  
  45. INSTRUCT:
  46. /* GIVE INSTRUCTIONS */
  47.     allocarexxlist
  48.         hSpecSizeList=result
  49.     addarexxlist hSpecSizeList '"One font per page"'
  50.     addarexxlist hSpecSizeList '"Six fonts per page"'
  51.     allocarexxlist
  52.         hWhichFontsList=result
  53.     addarexxlist hWhichFontsList '"All fonts"'
  54.     addarexxlist hWhichFontsList '"Selected fonts"'
  55.  
  56.     allocarexxrequester '"Create Font Specimen Sheets"' 552 115
  57.         hInstructReq=result
  58.     addarexxgadget hInstructReq EXIT 12 98 70 label "Print"
  59.         hPrintGadget=result
  60.     addarexxgadget hInstructReq EXIT 470 98 70 label "Cancel"
  61.         hCancelGadget=result
  62.     addarexxgadget hInstructReq TEXT 8 10 536 border none string "'This script will print font specimen sheets to help select fonts'"
  63.     addarexxgadget hInstructReq TEXT 8 22 536 border none string "'to use. You can choose to print detailed specimens with one font'"
  64.     addarexxgadget hInstructReq TEXT 8 34 536 border none string "'per page or small specimens with 6 fonts per page. You can also'"
  65.     addarexxgadget hInstructReq TEXT 8 46 536 border none string "'choose to print All installed fonts or Selected fonts only.'"
  66.     addarexxgadget hInstructReq CYCLE 64 70 188 label '"_Number"' labelpos left
  67.         hSpecSizeGadget=result
  68.     addarexxgadget hInstructReq CYCLE 384 70 156 label '"_Which Fonts"' labelpos left
  69.         hWhichFontsGadget=result
  70.     setarexxgadget hInstructReq hSpecSizeGadget list hSpecSizeList current 0
  71.     setarexxgadget hInstructReq hWhichFontsGadget list hWhichFontsList current 0
  72.  
  73.     doarexxrequester hInstructReq
  74.         action=result
  75.     if action=hCancelGadget then RETURN cancel
  76.  
  77.     getarexxgadget hInstructReq hSpecSizeGadget current
  78.         specsize=result
  79.  
  80.     getarexxgadget hInstructReq hWhichFontsGadget current
  81.         whichfonts=result
  82.  
  83.     freearexxrequester hInstructReq
  84.     freearexxlist hInstalledFontsList
  85.     freearexxlist hPrintFontsList
  86. RETURN 0
  87.  
  88. FINDFONTS:
  89. /* GET THE NAMES AND NUMBER OF FACES */
  90.     getfontlist ifonts
  91.     ifontcount=result
  92.  
  93.     /* Shuffle 0 to end to work with sort routine */
  94.     ifonts.ifontcount=ifonts.0
  95. RETURN
  96.  
  97. SORTIFONTS:
  98. /* SORT THE LIST ALPHABETICALLY */
  99.     DO tick = 1 to ifontcount-1
  100.         nexttick=tick+1
  101.         IF ifonts.tick > ifonts.nexttick THEN DO
  102.             store=ifonts.nexttick
  103.             ifonts.nexttick=ifonts.tick
  104.             DO bubpos = tick-1 to 1 by -1 WHILE (store < ifonts.bubpos)
  105.                 nexttick=bubpos+1
  106.                 ifonts.nexttick = ifonts.bubpos
  107.             END bubpos
  108.             bubpos=bubpos+1
  109.             ifonts.bubpos=store
  110.         END
  111.     END tick
  112. RETURN
  113.  
  114. SORTPFONTS:
  115. /* SORT THE LIST ALPHABETICALLY */
  116.         DO tick = 1 to pfontcount-1
  117.         nexttick=tick+1
  118.         IF pfonts.tick > pfonts.nexttick THEN DO
  119.             store=pfonts.nexttick
  120.             pfonts.nexttick=pfonts.tick
  121.             DO bubpos = tick-1 to 1 by -1 WHILE (store < pfonts.bubpos)
  122.                 nexttick=bubpos+1
  123.                 pfonts.nexttick = pfonts.bubpos
  124.             END bubpos
  125.             bubpos=bubpos+1
  126.             pfonts.bubpos=store
  127.         END
  128.     END tick
  129. RETURN
  130.  
  131. CHOOSEFONTS:
  132. /* FIND OUT WHICH FONTS TO PRINT */
  133.  
  134.     call alloclists()
  135.  
  136.     /* Initialize the installed font list */
  137.     do i=1 to ifontcount
  138.         'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  139.     end i
  140.  
  141.     /* Allocate and build the requester */
  142.     allocarexxrequester '"Create Font Specimen Sheets"' 528 211
  143.         hChooseReq=result
  144.     addarexxgadget hChooseReq TEXT 12 10 250 border none string "'Select the typefaces to print:'"
  145.     addarexxgadget hChooseReq EXIT 12 194 70 label "Print"
  146.         hPrintGadget=result
  147.     addarexxgadget hChooseReq EXIT 446 194 70 label "Cancel"
  148.         hCancelGadget=result
  149.     addarexxgadget hChooseReq EXIT 224 42 80 label '"_Add    ->"'
  150.         hAddGadget=result
  151.     addarexxgadget hChooseReq EXIT 224 62 80 label '"_Remove <-"'
  152.         hRemoveGadget=result
  153.     addarexxgadget hChooseReq SCROLLIST 12 42 200 139 label '"Installed Typefaces"' labelpos aboveleft
  154.         hInstalledFontsGadget=result
  155.     addarexxgadget hChooseReq SCROLLIST 316 42 200 139 label '"Typefaces to Print"' labelpos aboveleft
  156.         hPrintFontsGadget=result
  157.  
  158.     /* FONT SELECTION LOOP */
  159.     exitflag=0
  160.     do until exitflag=1
  161.  
  162.         /* Do the font selection requester */
  163.         setarexxgadget hChooseReq hInstalledFontsGadget list hInstalledFontsList current 0
  164.         setarexxgadget hChooseReq hPrintFontsGadget list hPrintFontsList current 0
  165.         doarexxrequester hChooseReq
  166.             action=result
  167.  
  168.         select
  169.             when action=hCancelGadget then do      /* THE USER CANCELLED   */
  170.                 call freelists()
  171.                 retvalue=9
  172.                 exitflag=1
  173.                 end
  174.             when action=hPrintGadget then do      /* PRINT THE FONTS!     */
  175.                 call freelists()
  176.                 retvalue=1
  177.                 exitflag=1
  178.                 end
  179.             when action=hAddGadget then do          /* ADD A FONT TO PRINT  */
  180.                 getarexxgadget hChooseReq hInstalledFontsGadget current
  181.                 cfont=result+1
  182.                 pfontcount=pfontcount+1
  183.                 pfonts.pfontcount=ifonts.cfont
  184.                 call sortpfonts()                  /* sort the to print list  */
  185.                 call freelists()                  /* free the arexx lists    */
  186.                 call alloclists()                  /* alloc the lists again   */
  187.                 do i=1 to pfontcount              /* fill the to print list  */
  188.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  189.                 end i
  190.                 do i=cfont to ifontcount          /* remove from ifonts      */
  191.                     nexti=i+1
  192.                     ifonts.i=ifonts.nexti
  193.                 end
  194.                 ifontcount=ifontcount-1
  195.                 do i=1 to ifontcount              /* fill the installed list */
  196.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  197.                 end i
  198.                 end
  199.             when action=hRemoveGadget then do       /* REMOVE A FONT TO PRINT */
  200.                 getarexxgadget hChooseReq hPrintFontsGadget current
  201.                 cfont=result+1
  202.                 ifontcount=ifontcount+1
  203.                 ifonts.ifontcount=pfonts.cfont
  204.                 call sortifonts()                  /* sort the installed list */
  205.                 call freelists()                  /* free the arexx lists    */
  206.                 call alloclists()                  /* alloc the lists again   */
  207.                 do i=1 to ifontcount              /* fill the installed list */
  208.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  209.                 end i
  210.                 do i=cfont to pfontcount          /* remove from pfonts      */
  211.                     nexti=i+1
  212.                     pfonts.i=pfonts.nexti
  213.                 end
  214.                 pfontcount=pfontcount-1
  215.                 do i=1 to pfontcount              /* fill the to print list  */
  216.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  217.                 end i
  218.                 end
  219.         end
  220.     end
  221.     freearexxrequester hChooseReq
  222.  
  223.     if retvalue=9 then EXIT
  224.     if retvalue=1 & pfontcount=0 then do
  225.         call doalert("No fonts selected to print!")
  226.         EXIT
  227.     end
  228.  
  229. RETURN
  230.  
  231. ALLOCLISTS:
  232. /* Allocate lists for the installed fonts and the fonts to print */
  233.     allocarexxlist
  234.         hInstalledFontsList=result     /* list of installed fonts */
  235.     allocarexxlist
  236.         hPrintFontsList=result         /* list of fonts to print */
  237. RETURN
  238.  
  239. FREELISTS:
  240. /* Free lists for the installed fonts and the fonts to print */
  241.     freearexxlist hInstalledFontsList
  242.     freearexxlist hPrintFontsList
  243. RETURN
  244.  
  245. PRINTFONTS:
  246. /* PRINT LOOP */
  247.     openbusyrequester message "'Creating Font Specimens...'" thermometer enabled abort enabled total 100 current 0
  248.         hBusyReq=result
  249.  
  250.     /* Count the pages to print */
  251.     if specsize=small then do
  252.         pagecount=trunc(pfontcount/6)
  253.         lastpage=(pfontcount/6-pagecount)*6            /* how many fonts on the last page?  */
  254.         if lastpage>0 then pagecount=pagecount+1    /* add a page if there's a remainder */
  255.         end
  256.     else pagecount=pfontcount
  257.  
  258.     /* Repeat for each page to print */
  259.     j=0
  260.     do i=1 to pagecount
  261.         j=j+1
  262.  
  263.         if specsize=small then do            /* Layout for 6 to a page */
  264.             do ii=1 to 6
  265.                 k=ii+(ii-1)*0.5             /* this gives us the correct offset */
  266.  
  267.                 if lastpage>0 & i=pagecount & ii>lastpage then do
  268.                     /* Change the title(s) to blank */
  269.                     'setvariablevalue "' '" variable FontName'ii
  270.                     /* Set the text color to white */
  271.                     'beginstyletag styletag FontSample'ii
  272.                     'setcolor text white styletag FontSample'ii
  273.                     'endstyletag styletag FontSample'ii
  274.                     end
  275.                 else do
  276.                     /* Change the title(s) */
  277.                     'setvariablevalue "'pfonts.j'" variable FontName'ii
  278.                     /* Change the font */
  279.                     'beginstyletag styletag FontSample'ii
  280.                     'setfont "'pfonts.j'" styletag FontSample'ii
  281.                     'endstyletag styletag FontSample'ii
  282.                 end
  283.                 j=j+1
  284.             end ii
  285.             j=j-1
  286.             end
  287.         else do
  288.             /* Change the title */
  289.             'setvariablevalue "'pfonts.j'" variable FontName'
  290.             /* Change the font */
  291.             'beginstyletag styletag FontSample'
  292.             'setfont "'pfonts.j'" styletag FontSample'
  293.             'endstyletag styletag FontSample'
  294.         end
  295.  
  296.         /* Print the font sample page */
  297.         'printdocument copies 1 page 1 sides both scale actual output grayscale printermarks off mirror off negative off document 'sDocName
  298.         call setbusy(i/pagecount*100)
  299.     end i
  300.  
  301.     'closebusyrequester 'hBusyReq
  302.     'closedocument force'
  303. RETURN
  304.  
  305. DOALERT:
  306. parse arg astring
  307. /* Display an alert requester */
  308.         allocarexxrequester '"Script Alert"' 334 55
  309.             hAlertReq=result
  310.         addarexxgadget hAlertReq TEXT 8 12 268 border none string '"'astring'"'
  311.         addarexxgadget hAlertReq EXIT 252 38 70 label "Exit"
  312.         doarexxrequester hAlertReq
  313.         freearexxrequester hAlertReq
  314. RETURN
  315.  
  316. SETBUSY:
  317.     parse arg value
  318.     ADDRESS PAGESTREAM
  319.     setbusyrequester hBusyReq current value
  320.     getbusyrequester hBusyReq
  321.     if result=1 then call CLEANUP(1)
  322.     ADDRESS COMMAND
  323. RETURN
  324.  
  325. CLEANUP:
  326.     'closebusyrequester 'hBusyReq
  327.     'closedocument force'
  328. EXIT
  329.